<?php


namespace App\Exceptions;


use Throwable;

class APIErrorException extends \Exception
{
    const TYPE_VALIDATE_ERROR = 1;
    const TYPE_SIGN_ERROR = 2;
    const TYPE_DATABASE_ERROR =3;
    const TYPE_LOGIN = 4;
    protected $type ;

    public function __construct($type,$message = "", $code = 0, Throwable $previous = null)
    {
        $this->type = $type;
        parent::__construct($message, $code, $previous);
    }

    public static function newValidate($message,$code=0): APIErrorException
    {
        return new static(static::TYPE_VALIDATE_ERROR,$message,$code);
    }

    public static function newSign($message,$code=0): APIErrorException
    {
        return new static(static::TYPE_SIGN_ERROR,$message,$code);
    }

    public static function newDatabase($message,$code=0): APIErrorException
    {
        return new static(static::TYPE_DATABASE_ERROR,$message,$code);
    }

    public static function newLogin($msg,$code=2):APIErrorException
    {
        return new static(static::TYPE_LOGIN,$msg,$code);
    }

    public function isLogin(): bool
    {
        return $this->type == self::TYPE_LOGIN;
    }

}
